/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * Configurações.java
 *
 * Created on Jun 4, 2012, 10:39:31 PM
 */
package br.ufrn.dca.interfaceGrafica;

import br.ufrn.dca.Comunicacao.TipoPlanta;
import br.ufrn.dca.observador.TipoObservador;

/**
 *
 * @author allan
 */
public class JanelaConfigurações extends javax.swing.JDialog {

    private Janela jn;

    /** Creates new form Configurações */
    public JanelaConfigurações(java.awt.Frame parent, boolean modal, Janela jn) {
        super(parent, modal);
        initComponents();
        this.jn = jn;
        this.setLocationRelativeTo(jn);
        this.jOBS_ONLINE.setSelected(true);
        this.jPLANTA_LINEAR.setSelected(true);
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        GroupTipoPlanta = new javax.swing.ButtonGroup();
        GroupTipoObs = new javax.swing.ButtonGroup();
        jPanel1 = new javax.swing.JPanel();
        jOBS_ONLINE = new javax.swing.JRadioButton();
        jOBS_LINEAR = new javax.swing.JRadioButton();
        jPanel2 = new javax.swing.JPanel();
        jPLANTA_REAL = new javax.swing.JRadioButton();
        jPLANTA_LINEAR = new javax.swing.JRadioButton();
        jSIMULADOR = new javax.swing.JRadioButton();
        jButtonOK = new javax.swing.JButton();
        jButtonCANCELAR = new javax.swing.JButton();

        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Tipo de Observador", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 1, 12))); // NOI18N
        jPanel1.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N

        GroupTipoObs.add(jOBS_ONLINE);
        jOBS_ONLINE.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        jOBS_ONLINE.setText("Observador Online");
        jOBS_ONLINE.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jOBS_ONLINEActionPerformed(evt);
            }
        });

        GroupTipoObs.add(jOBS_LINEAR);
        jOBS_LINEAR.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        jOBS_LINEAR.setText("Observador Linear");
        jOBS_LINEAR.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jOBS_LINEARActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jOBS_ONLINE)
                    .addComponent(jOBS_LINEAR))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(22, 22, 22)
                .addComponent(jOBS_ONLINE)
                .addGap(18, 18, 18)
                .addComponent(jOBS_LINEAR)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Tipo de Planta", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 1, 12))); // NOI18N

        GroupTipoPlanta.add(jPLANTA_REAL);
        jPLANTA_REAL.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        jPLANTA_REAL.setText("Planta Real");

        GroupTipoPlanta.add(jPLANTA_LINEAR);
        jPLANTA_LINEAR.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        jPLANTA_LINEAR.setText("Planta linear");
        jPLANTA_LINEAR.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jPLANTA_LINEARActionPerformed(evt);
            }
        });

        GroupTipoPlanta.add(jSIMULADOR);
        jSIMULADOR.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        jSIMULADOR.setText("Simulador");
        jSIMULADOR.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jSIMULADORActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jPLANTA_REAL)
                    .addComponent(jSIMULADOR)
                    .addComponent(jPLANTA_LINEAR))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addComponent(jPLANTA_REAL)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jSIMULADOR)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jPLANTA_LINEAR)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jButtonOK.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        jButtonOK.setText("OK");
        jButtonOK.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonOKActionPerformed(evt);
            }
        });

        jButtonCANCELAR.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        jButtonCANCELAR.setText("Cancelar");
        jButtonCANCELAR.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonCANCELARActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                        .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jButtonOK)
                        .addGap(18, 18, 18)
                        .addComponent(jButtonCANCELAR)))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButtonCANCELAR)
                    .addComponent(jButtonOK))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
    }// </editor-fold>//GEN-END:initComponents

    private void jOBS_ONLINEActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jOBS_ONLINEActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jOBS_ONLINEActionPerformed

    private void jOBS_LINEARActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jOBS_LINEARActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jOBS_LINEARActionPerformed

    private void jPLANTA_LINEARActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jPLANTA_LINEARActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jPLANTA_LINEARActionPerformed

    private void jSIMULADORActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jSIMULADORActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jSIMULADORActionPerformed

    private void jButtonOKActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonOKActionPerformed
        // TODO add your handling code here:
        configureOBS();
        configurePLANTA();
        jn.setConfigurado(true);
        this.dispose();
    }//GEN-LAST:event_jButtonOKActionPerformed

    private void jButtonCANCELARActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonCANCELARActionPerformed
        // TODO add your handling code here:
        this.dispose();
    }//GEN-LAST:event_jButtonCANCELARActionPerformed
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.ButtonGroup GroupTipoObs;
    private javax.swing.ButtonGroup GroupTipoPlanta;
    private javax.swing.JButton jButtonCANCELAR;
    private javax.swing.JButton jButtonOK;
    private javax.swing.JRadioButton jOBS_LINEAR;
    private javax.swing.JRadioButton jOBS_ONLINE;
    private javax.swing.JRadioButton jPLANTA_LINEAR;
    private javax.swing.JRadioButton jPLANTA_REAL;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JRadioButton jSIMULADOR;
    // End of variables declaration//GEN-END:variables

    private void configureOBS() {
        if (jOBS_LINEAR.isSelected()) {
            jn.setT_Obs(TipoObservador.LINEAR);
            jn.setObsLinear();

        } else {
            jn.setT_Obs(TipoObservador.ONLINE);
            jn.setObsOnline();
        }
    }

    private void configurePLANTA() {
        if (jPLANTA_LINEAR.isSelected()) {
            jn.setT_Planta(TipoPlanta.LINEAR);
//            jn.getObs().setXeq_1(15.0044);
        } else if (jPLANTA_REAL.isSelected()) {
            jn.setT_Planta(TipoPlanta.REAL);
            jn.setClientePlantaReal();
        } else {
            jn.setT_Planta(TipoPlanta.SIMULADOR);
            jn.setClienteSimulador();
//            jn.getObs().setXeq_1(14.77);
        }
    }
}
